<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="../vue/element-plus/index.css" />
    <style>
      .mybtn {
        color: red;
        height: 30px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <!-- 组件 -->
      <el-button type="primary">按钮</el-button>
      <my-button> </my-button>
      <my-button></my-button>

      <component-a>
        <component-b></component-b>
      </component-a>
      <component-b></component-b>
    </div>
    <script src="../vue/vue.global.js"></script>
    <script src="../vue/element-plus/index.js"></script>
    <script>
      const componentB = {
        template: `<div>组件B</div><component-a></component-a>`,
      };
      const componentA = {
        components: {
          "component-b": componentB,
        },
        template: `<div>组件A</div> <component-b></component-b>`,
      };

      const app = Vue.createApp({
        components: {
          // 局部注册
          "component-a": componentA,
          "component-b": componentB,
        },
      });
      app.use(ElementPlus);

      // 自定义组件, 全局注册: app.component在整个应用中都可以使用
      app.component("my-button", {
        // 数据
        data() {
          return {
            count: 0,
          };
        },
        methods: {
          clickHanlder() {
            this.count++;
          },
        },
        // 模板
        template: `<button class='mybtn' @click='clickHanlder'>点击次数：{{ count }} <my-span></my-span></button>`,
      });
      app.component(`my-span`, {
        // 模板
        template: `<span>自定义span</span>`,
      });
      app.mount("#app");
    </script>
  </body>
</html>
